package com.yitiao.socket.chatroom.demo;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws Exception {
        Socket client = new Socket("127.0.0.1", 8889);

        BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));   // 装饰器模式
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));

        // 等待用户的信息
        BufferedReader systemReader = new BufferedReader(new InputStreamReader(System.in));

        String line = systemReader.readLine();
        if (line!=null){
            writer.write(line+"\n");
            writer.flush();
        }

        String back = reader.readLine();
        System.out.println(back);

        client.close();

    }
}
